package com.pangu.message;

import cn.hutool.core.lang.UUID;
import com.google.common.collect.Maps;
import lombok.Getter;
import lombok.Setter;

import java.util.Map;

import static java.lang.System.currentTimeMillis;
import static java.util.Objects.isNull;


/**
 * @author Linbizhao
 * @description: 消息抽象类
 * @since 2023/11/23 15:57
 */
@Getter
@Setter
public class PanguMessage<T extends Message> implements Message {

    /**
     * 消息标识
     */
    protected String sn = UUID.fastUUID().toString(true);

    /**
     * 时间戳
     */
    protected long timestamp = currentTimeMillis();

    /**
     * 头部信息
     */
    protected volatile Map<String, Object> headers = Maps.newConcurrentMap();

    @Override
    public String getUniqueCode() {
        return null;
    }

    @Override
    public Map<String, Object> getData() {
        return null;
    }

    @Override
    public Map<String, Object> getHeaders() {
        if (isNull(headers)) {
            synchronized (this) {
                if (isNull(headers)) {
                    this.headers = Maps.newConcurrentMap();
                }
            }
        }
        return this.headers;
    }

    @Override
    public Message addHeader(String header, Object value) {
        return null;
    }

    @Override
    public Message removeHeader(String header) {
        return null;
    }
}
